package cn.hhchat.wp.service;

import cn.hhchat.wp.entity.CommentEntity;
import cn.hhchat.wp.entity.PostEntity;
import cn.hhchat.wp.entity.UserEntity;
import cn.hhchat.wp.repository.CommentRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * Created this one by HMH on 2017/10/23.
 */
@Service
public class CommentService {


    public CommentEntity createOne(UserEntity user, PostEntity post, String content) {
        CommentEntity comment = new CommentEntity();
        comment.setComment(content);
        comment.setCommenter(user);
        comment.setPost(post);
        post.getComments().add(comment);
        return save(comment);
    }

    public CommentEntity save(CommentEntity comment) {
        return commentRepository.save(comment);
    }

    @Autowired
    CommentRepository commentRepository;

}
